package aop.test.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * Created by Stimd
 * 项目地址：https://gitee.com/stimd/spring-wheel
 * 公众号：Java编程探微
 */
public class SimpleMethodInterceptor implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation mi) throws Throwable {
        Object result;
        String methodName = mi.getMethod().getName();
        try {
            System.out.println("前置拦截，方法名：" + methodName);
            result = mi.proceed();
        }catch (Exception e) {
            System.out.println("异常拦截，方法名：" + methodName);
            throw e;
        }
        System.out.println("返回拦截，方法名：" + methodName);
        return result;
    }
}
